<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>再融资合同明细信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="contDetailInfo">
				<div class="fieldset1 tabel_col clearFix">
					<div class="fieldBox col_50">
						<div class="label">合同名称</div>
						<div class="field">
							<input name="contDetailNm" id="contDetailNm" type="text" class="ui-textbox" ligerui="width: 160" value="${ContDetailVo.contDetailNm }" validate="{required:true}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">审核状态</div>
						<div class="field">
							<select name="contDetailStatus" id="contDetailStatus" ligerui="width: 160">
								<c:forEach items="${contStsList}" var="item">
									<c:if test='${ContDetailVo.contDetailStatus == item.key}'>  
										<option value="${item.key }" selected="selected" >${item.value }</option>
									</c:if>
									<c:if test='${ContDetailVo.contDetailStatus != item.key}'>  
										<option value="${item.key }" >${item.value }</option>
									</c:if>
								</c:forEach>
							</select>
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">主合同编号</div>
						<div class="field">
							<input name="mainContractNo" id="mainContractNo" type="text" class="ui-textbox" ligerui="width: 160" value="${ContDetailVo.mainContractNo }" validate="{required:true,maxlength:64}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">合同备注</div>
						<div class="field">
							<textarea name="contDetailRemark" id="contDetailRemark" rows="3" class="ui-textarea l-textarea" style="width:98%" value="" ></textarea>
						</div>
					</div>
					<!-- 上传附件 -->
					<div class="fieldBox col_100">
						<div class="label">附件上传</div>
						<div class="field">
							<jsp:include page="../frCommFilesUpload.jsp" flush="true" >
								<jsp:param name="filePath" value="ref"/>
							</jsp:include>
							<div id="fileUpload1" class="upfileBoxs"></div>
							<span class="sq-button sq-button-hasicon" id="btnUpload1" onclick="ajaxFileUploadImg('uploads1',1)">
								<i class="sqBtnIco_9"></i>上传
							</span>
						</div>
					</div>
					<!-- 附件显示 -->
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
			            	<jsp:include page="../frCommFilesList.jsp" flush="true" ></jsp:include>
							<div id="ligergrid_file1" class="sq-grid"></div>
						</div>
					</div>
					<!-- 隐藏支付表主键、支付表号 -->
	                <div class="fieldBox col_100" style="display:none;">
	                    <div class="field">
	                         <!-- 上传文件使用：系统时间和当前登录人姓名 -->
	                         <input name="sysDate" id="sysDate" type="text" class="ui-textbox" value="${sysDate }">
	                         <input name="loginUsrNm" id="loginUsrNm" type="text" class="ui-textbox" value="${loginUsrNm }">
	                    </div>
	                </div>
    			</div>
    			<div class="fieldset1 clearFix">
					<div class="btnsBox" style="text-align: center;">
						<span id="saveBtn" class="sq-button sq-button-round" onclick="saveContDetail()">保存</span>
						<span id="closeBtn" class="sq-button sq-button-round" onclick="closeDialog()">取消</span>
						<input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
	   				</div>
   				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		$(function() {
			initForm();//初始化表单
	    });
		
		//初始化表单数据
		function initForm(){
	    	$("#contDetailInfo").ligerForm({
				validate: true
			});//初始化表单
			//初始化数据
			if(null!="${id }" && ""!="${id }" && null!="${ContDetailVo }"){
				//修改合同备注显示方式（解决空格和回车不可识别问题）-JL-20190821
				$.ajax({
			   		type: 'get',
			   		dataType:'json',
			   		data:{
			   			id:"${id }"
			   		},
			   		url: '<%=path%>/rfbuss/fncPrjContDetail/getById.do?',
			   		success:function(msg){
						if(msg.success == 1){
							//加载表单
					    	var form = liger.get("contDetailInfo");
							form.setData({
								contDetailNm: msg.data.contDetailNm,
								contDetailStatus: msg.data.contDetailStatus
					    	});
							$("#contDetailRemark").val(msg.data.contDetailRemark);
						}else{
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
						}
					}
				});
			}else{
				//新增审核状态不可编辑
				liger.get("contDetailStatus").setDisabled(true);
			}
			//加载合同附件列表信息
			var contDetailStatus = $("#contDetailStatus").val();
			if(contDetailStatus == "0" || contDetailStatus == "4"){
		    	//附件可删除
		    	loadFilesLiger("htfj", 1, "${ContDetailVo.id }", "yes");
			}else{
		    	//附件不可删除
		    	loadFilesLiger("htfj", 1, "${ContDetailVo.id }", "no");
			}
		}
		
		//保存合同信息（再融资合同明细表）
		function saveContDetail(){
			var ligerForm = liger.get("contDetailInfo");
			if (!ligerForm.valid()) {
				top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return false; //验证不通过，不执行以下代码
			}
			$.ligerDialog.confirm('确定保存合同信息吗?', function (flag) {
				if(flag == false)return;
			   //获取表单数据
				var data = ligerForm.getData();
				data["contId"] = "${contId }";//合同主表ID
				data["id"] = "${id }";//合同明细表ID
				data["fncPrjId"] = "${fncPrjId }";//项目编号
				//新增-修改合同明细表数据
				var wait_dialog = null;
				var url = '<%=path%>/rfbuss/fncPrjContDetail/saveContract.do';
				$.ajax({
					type: 'post',
					dataType: 'json',
					data: data,
					url: url,
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						wait_dialog.close();
						//返回的合同明细表ID不为空执行一下操作
						if(msg.success == 1 && null != msg.data &&  null != msg.id){
							saveFile(msg.data,msg.info,msg.id);//保存文件
						}else{
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					}
				});
			});
		}
		
		//显示已上传但是未保存的文件列表
		function showFiles(data, index){
			var sysDate = $("#sysDate").val();
			var loginUsrNm = $("#loginUsrNm").val();
			var f_Grid = liger.get("ligergrid_file"+index);
			var uploadJOSN = data;
    		for (var i=0; i< uploadJOSN.length; i++){ 
        		//添加行-追加行
        		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: i});
    		}
		}
		
		//保存文件
		function saveFile(pkId,info,mainId){
			var docArray = JSON.stringify(getUploadResultParams(1));
	        var url = "<%=path%>/rfbuss/fncPrjContDetail/uploadAttchment.do";
        	if(null == docArray){
        		//无要上传的文件-直接结束
        		top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
        		//Remove_navTab();//关闭申请窗口
        		frameElement.dialog._DATA={mainId:mainId};//给父窗口的dialog传参
        		frameElement.dialog.close();//关闭对话框
        	}else{
		        if(pkId){//拖车主表ID不为空执行
			        //赋值附件
			        var data = {
						"docArray":docArray,
						"pkId": pkId,
						"flag": "htfj"
					};
					//请求
			        AjaxUtils.ajaxPost(url, data, function(msg){
			        	if(msg.success == 1){
							 top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
							 if(msg.data){
								 //清空上传文件缓存
								 clearUploadResultParams(1);
							 }
							 //Remove_navTab();//关闭申请窗口
        					 frameElement.dialog._DATA={mainId:mainId};//给父窗口的dialog传参
							 frameElement.dialog.close();//关闭对话框
						 }else{
							 UIUtils.alertError(msg.info);
						 }
			        }, true);
		        }else{
		        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
		        }
        	}
		}
		
		//取消/关闭当前对话框
		function closeDialog(){
			frameElement.dialog.close();
		}
	</script>
</body>
</html>